<template>
  <div class="login-background">
    <div class="login">
      <div class="log-title">登录</div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" :status-icon="true">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="ruleForm.userName" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="userPass">
          <el-input type="password" v-model="ruleForm.userPass" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">登录</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        ruleForm: {
          userName : 'admin',
          userPass : 'admin',
        },
        rules: {
          userName: [
            {required: true, message: '请输入用户名', trigger: 'blur'},
            {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
          ],
          userPass: [
            {required: true, message: '请输入密码', trigger: 'blur'},
            {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
          ]
        }
      };
    },
    methods: {
      submitForm() {
        this.$refs["ruleForm"].validate((valid) => {
          if (valid) {
            this.$message.success('登录成功');
            this.$router.push('/');
          } else {
            return false;
          }
        });
      },
      resetForm() {
        this.$refs["ruleForm"].resetFields();
      }
    }
  }
</script>
<style>
  .login-background{width: 100%;height:100%;background: url('../../static/img/login-bg.jpg') center center no-repeat;}
  .login{width:400px;position:fixed;right:100px;top:200px;
    padding:20px;border:1px solid #ccc;background:#fff;
  }
  .log-title{font-size:24px;color:#333;padding:0px 0px 20px 0;text-align:center;letter-spacing: 20px;
  }
</style>
